﻿Imports System.Reflection
Namespace ControlLibrary
    ''' <summary>Creates a generic control that displays all the info in a dbiWSFObject</summary>
    Public Class dbiWSFObjectDetail

#Region "**Events**"
        ''' <summary>Raised when a TextBox changes.</summary>
        Public Event TextBoxChanged(ByRef sender As Object, ByRef e As System.EventArgs)

        ''' <summary>Raised when a FloatingPointTextBox changes.</summary>
        Public Event TextBoxFloatChanged(ByRef sender As Object, ByRef e As System.EventArgs)

        ''' <summary>Raised when a NumericSpinner changes.</summary>
        Public Event NumericValueChanged(ByRef sender As Object, ByRef e As System.EventArgs)

        ''' <summary>Raised when a DateTime control changes.</summary>
        Public Event DateTimeChanged(ByRef sender As Object, ByRef e As System.EventArgs)

        ''' <summary>Raised when a FloatingPointMaskedEdit changes.</summary>
        Public Event MaskFloatChanged(ByRef sender As Object, ByRef e As System.EventArgs)

        ''' <summary>Raised when a DaysOfWeek control changes.</summary>
        Public Event DaysOfWeekValidating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs, ByVal DaysOfWeek() As Byte)
#End Region

#Region "**Properties**"

        ''' <summary>A collection used to house the controls before they are added to the form.</summary>
        ''' <remarks>This is marked as public in case developers need access to the raw control collections for
        ''' advanced data types.</remarks>
        Public ControlsToAdd As New System.Collections.Generic.List(Of dbiWSF.UserInterface.DisplayControl)

        Private l_LastBottom As Long
        Private l_MaxLabel As Long
        Private l_dbiWSFObjectToDisplay As Object
        Private l_WSFObject As dbiWSF.FrameworkObjects.objWSFObjects
        Private l_UseMaskForDecimals As Boolean = True


        ''' <summary>Used to calculate the next top position for the next control in the list.</summary>
        Public Property LastBottom() As Long
            Get
                Return l_LastBottom
            End Get
            Set(ByVal value As Long)
                l_LastBottom = value
            End Set
        End Property

        ''' <summary>The maximum width of the description label.</summary>
        Public Property MaxLabel() As Long
            Get
                Return l_MaxLabel
            End Get
            Set(ByVal value As Long)
                l_MaxLabel = value
            End Set
        End Property

        ''' <summary>The dbiWSFObject to display.</summary>
        Public Property dbiWSFObjectToDisplay()
            Get
                Return l_dbiWSFObjectToDisplay
            End Get
            Set(ByVal value)
                l_dbiWSFObjectToDisplay = value
            End Set
        End Property

        ''' <summary>The main dbiWSFObject for use with this control.</summary>
        Public Property WSFObject() As dbiWSF.FrameworkObjects.objWSFObjects
            Get
                Return l_WSFObject
            End Get
            Set(ByVal value As dbiWSF.FrameworkObjects.objWSFObjects)
                l_WSFObject = value
            End Set
        End Property

        ''' <summary>Determines if the control uses a standard text box or a masked edit for decimal values.</summary>
        Public Property UseMaskForDecimals() As Boolean
            Get
                Return l_UseMaskForDecimals
            End Get
            Set(ByVal value As Boolean)
                l_UseMaskForDecimals = value
            End Set
        End Property

#End Region

#Region "--Display Methods--"


        ''' <summary>Displays a dbiWSF Object in the control.</summary>
        Public Sub DisplayObject(ByRef ObjectToDisplay As Object, ByRef ParentWSFObject As dbiWSF.FrameworkObjects.objWSFObjects)
            Me.Controls.Clear()
            Me.Refresh()

            dbiWSFObjectToDisplay = ObjectToDisplay
            WSFObject = ParentWSFObject

            Select Case dbiWSFObjectToDisplay.GetType.ToString
                Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                    DisplayWarehouse(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                    DisplayLoadingDock(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objShipment).ToString
                    DisplayShipment(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objOrderHeader).ToString
                    DisplayOrderHeader(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objOrderDetail).ToString
                    DisplayOrderDetail(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objRecurrence).ToString
                    DisplayRecurrence(dbiWSFObjectToDisplay)
                Case GetType(dbiWSF.FrameworkObjects.objLoadingDockException).ToString
                    DisplayLoadingDockException(dbiWSFObjectToDisplay)

            End Select
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayWarehouse(ByRef WarehouseToDisplay As dbiWSF.FrameworkObjects.objWarehouse)
            ControlsToAdd.Clear()


            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In WarehouseToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapWarehouses, curColumn.ColumnName)
                Try
                    PropInfo = WarehouseToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(WarehouseToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()

        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayLoadingDock(ByRef LoadingDockToDisplay As dbiWSF.FrameworkObjects.objLoadingDock)
            ControlsToAdd.Clear()
            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In LoadingDockToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapLoadingDocks, curColumn.ColumnName)
                Try
                    PropInfo = LoadingDockToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(LoadingDockToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayLoadingDockException(ByRef LoadingDockExceptionToDisplay As dbiWSF.FrameworkObjects.objLoadingDockException)
            ControlsToAdd.Clear()
            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In LoadingDockExceptionToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapLoadingDockExceptions, curColumn.ColumnName)
                Try
                    PropInfo = LoadingDockExceptionToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(LoadingDockExceptionToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayShipment(ByRef ShipmentToDisplay As dbiWSF.FrameworkObjects.objShipment)
            ControlsToAdd.Clear()
            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In ShipmentToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapShipments, curColumn.ColumnName)
                Try
                    PropInfo = ShipmentToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(ShipmentToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayOrderHeader(ByRef OrderHeaderToDisplay As dbiWSF.FrameworkObjects.objOrderHeader)
            ControlsToAdd.Clear()


            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In OrderHeaderToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapOrderHeaders, curColumn.ColumnName)
                Try
                    PropInfo = OrderHeaderToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(OrderHeaderToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayOrderDetail(ByRef OrderDetailToDisplay As dbiWSF.FrameworkObjects.objOrderDetail)
            ControlsToAdd.Clear()
            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In OrderDetailToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapOrderDetails, curColumn.ColumnName)
                Try
                    PropInfo = OrderDetailToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(OrderDetailToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()
        End Sub

        ''' <summary>Supporting Method: Displays an individual object, called from DisplayObject</summary>
        Private Sub DisplayRecurrence(ByRef RecurrenceToDisplay As dbiWSF.FrameworkObjects.objRecurrence)
            ControlsToAdd.Clear()
            Dim curColumn As DataColumn
            Dim PropInfo As PropertyInfo

            For Each curColumn In RecurrenceToDisplay.AttachedDataRow.Table.Columns
                Dim newCtrl As New dbiWSF.UserInterface.DisplayControl
                newCtrl.ActualDataColumn = curColumn
                newCtrl.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapRecurrences, curColumn.ColumnName)
                Try
                    PropInfo = RecurrenceToDisplay.GetType.GetProperty(newCtrl.LabelString)
                    If Not PropInfo Is Nothing Then
                        CalcControl(curColumn, PropInfo.GetValue(RecurrenceToDisplay, Nothing), newCtrl)
                        ControlsToAdd.Add(newCtrl)
                    End If
                Catch ex As Exception
                    '<GenericError> Modify as needed
                    Throw New Exception("There was an error mapping the data: " + curColumn.ColumnName, ex)
                End Try
            Next
            AddControls()

            Dim ctrlDaysOfWeek As New dbiWSF.ControlLibrary.RecurrenceDaysOfWeek(RecurrenceToDisplay.DaysOfWeek)
            ctrlDaysOfWeek.Top = LastBottom + 10
            ctrlDaysOfWeek.Left = 10 + MaxLabel + 10 '(Initial left pos + maxlabelwidth + padding)
            Dim ctrlInfo As New dbiWSF.UserInterface.DisplayControl
            ctrlInfo.LabelString = WSFObject.WSFDatabinding.GetColumnMap(WSFObject.WSFDatabinding.cmapRecurrences, "DaysOfWeek")
            ctrlInfo.ActualDataColumn = RecurrenceToDisplay.AttachedDataRow.Table.Columns("DaysOfWeek")

            ctrlDaysOfWeek.Tag = ctrlInfo

            AddHandler ctrlDaysOfWeek.DaysOfWeekValidating, AddressOf l_DaysOfWeekValidating
            Me.Controls.Add(ctrlDaysOfWeek)
            LastBottom = ctrlDaysOfWeek.Bottom

        End Sub

#End Region

#Region "--Supporting Methods--"

        ''' <summary>Supporting Method: Determines the type of control to create based on the property type.</summary>
        Private Sub CalcControl(ByVal curCol As DataColumn, ByVal controlval As Object, ByRef curDisplayCtrl As dbiWSF.UserInterface.DisplayControl)
            DeNullVal(controlval, curCol)
            Select Case curCol.DataType.ToString
                Case GetType(System.Guid).ToString
                    NewLabelForGUID(curDisplayCtrl, controlval, curCol.MaxLength)
                Case GetType(System.String).ToString
                    NewTextBox(curDisplayCtrl, controlval, curCol.MaxLength)
                Case GetType(System.Int64).ToString
                    Dim curProp As PropertyInfo
                    curProp = dbiWSFObjectToDisplay.GetType.GetProperty(curDisplayCtrl.LabelString)
                    If curProp.PropertyType.IsEnum Then
                        NewComboBox(curDisplayCtrl, controlval, curProp)
                    Else
                        NewNumericUpDown(curDisplayCtrl, controlval)
                    End If
                Case GetType(System.Int32).ToString
                    Dim curProp As PropertyInfo
                    curProp = dbiWSFObjectToDisplay.GetType.GetProperty(curDisplayCtrl.LabelString)
                    If curProp.PropertyType.IsEnum Then
                        NewComboBox(curDisplayCtrl, controlval, curProp)
                    Else
                        NewNumericUpDown(curDisplayCtrl, controlval)
                    End If
                Case GetType(System.DateTime).ToString
                    NewdbiDateTime(curDisplayCtrl, controlval)
                Case GetType(System.Double).ToString
                    If UseMaskForDecimals = True Then
                        NewMaskFloat(curDisplayCtrl, controlval, False, 3)
                    Else
                        NewTextFloat(curDisplayCtrl, controlval)
                    End If
            End Select

        End Sub

        Private Sub DeNullVal(ByRef curVal As Object, ByVal curCol As DataColumn)
            Select Case curCol.DataType.ToString
                Case GetType(System.Guid).ToString
                    If curVal Is Nothing Then
                        curVal = Guid.NewGuid
                    End If
                Case GetType(System.String).ToString
                    If curVal Is Nothing Then
                        curVal = ""
                    End If
                Case GetType(System.Int64).ToString
                    If curVal Is Nothing Then
                        curVal = 0
                    End If
                Case GetType(System.Int32).ToString
                    If curVal Is Nothing Then
                        curVal = 0
                    End If
                Case GetType(System.DateTime).ToString
                    If curVal Is Nothing Then
                        curVal = System.DateTime.MinValue
                    End If
                Case GetType(System.Double).ToString
                    If curVal Is Nothing Then
                        curVal = 0
                    End If
            End Select
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewComboBox(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object, ByVal curPropInfo As PropertyInfo)
            Dim l_newCombo As New System.Windows.Forms.ComboBox
            DisplayControlToUse.ControlValue = controlValue

            l_newCombo.DataSource = System.Enum.GetValues(curPropInfo.PropertyType)

            l_newCombo.Width = 250
            l_newCombo.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_newCombo
            'AddHandler l_newCombo.TextChanged, AddressOf l_TextBoxChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewTextBox(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object, ByVal MaxChar As Long)
            Dim l_newText As New System.Windows.Forms.TextBox
            DisplayControlToUse.ControlValue = controlValue
            l_newText.Text = controlValue.ToString
            If MaxChar > 100 Then
                l_newText.Multiline = True
                l_newText.Height = l_newText.PreferredHeight * 3
            Else
                l_newText.Multiline = False
            End If
            l_newText.Width = 250
            l_newText.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_newText
            AddHandler l_newText.TextChanged, AddressOf l_TextBoxChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewLabelForGUID(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object, ByVal MaxChar As Long)
            Dim l_newText As New System.Windows.Forms.TextBox
            DisplayControlToUse.ControlValue = controlValue
            l_newText.Text = controlValue.ToString
            If MaxChar > 100 Then
                l_newText.Multiline = True
                l_newText.Height = l_newText.PreferredHeight * 3
            Else
                l_newText.Multiline = False
            End If
            l_newText.Width = 250
            l_newText.Tag = DisplayControlToUse
            l_newText.ReadOnly = True
            l_newText.BackColor = Drawing.Color.LightGray

            DisplayControlToUse.ControlType = l_newText
            AddHandler l_newText.TextChanged, AddressOf l_TextBoxChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewTextFloat(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object)
            Dim l_NewTextFloat As New System.Windows.Forms.TextBox
            DisplayControlToUse.ControlValue = controlValue.ToString
            l_NewTextFloat.Text = controlValue.ToString

            l_NewTextFloat.Multiline = False

            l_NewTextFloat.Width = 75
            l_NewTextFloat.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_NewTextFloat
            AddHandler l_NewTextFloat.TextChanged, AddressOf l_TextBoxFloatChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewNumericUpDown(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object)
            Dim l_newNumber As New System.Windows.Forms.NumericUpDown
            DisplayControlToUse.ControlValue = controlValue
            l_newNumber.Maximum = 999999
            l_newNumber.Value = CLng(controlValue)
            l_newNumber.Width = 6 * l_newNumber.Font.SizeInPoints + 10
            l_newNumber.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_newNumber
            AddHandler l_newNumber.ValueChanged, AddressOf l_NumericValueChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewdbiDateTime(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object)
            Dim l_newdbiDate As New dbiWSF.ControlLibrary.dbiDateTime(controlValue)
            DisplayControlToUse.ControlValue = controlValue
            l_newdbiDate.Width = 300
            l_newdbiDate.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_newdbiDate
            AddHandler l_newdbiDate.DateValueChanged, AddressOf l_DateTimeChanged
        End Sub

        ''' <summary>Supporting Method: Creates the control that is specific to the type of the property being displayed.</summary>
        Private Sub NewMaskFloat(ByRef DisplayControlToUse As dbiWSF.UserInterface.DisplayControl, ByVal controlValue As Object, ByVal UseCurrency As Boolean, ByVal DecimalPlaces As Integer)
            Dim strDecimalPlaces As String
            Dim maskToUse As String

            Dim l_newMask As New Windows.Forms.MaskedTextBox
            DisplayControlToUse.ControlValue = controlValue
            l_newMask.Width = 70
            'Determines the layout for the mask
            If DecimalPlaces > 0 Then
                strDecimalPlaces = ".0000000000".Substring(0, DecimalPlaces + 1)
            Else
                strDecimalPlaces = ""
            End If
            If UseCurrency = True Then
                maskToUse = "$000000" + strDecimalPlaces
            Else
                maskToUse = "000000" + strDecimalPlaces
            End If
            l_newMask.Mask = maskToUse
            l_newMask.Text = Format(controlValue, maskToUse)
            l_newMask.Tag = DisplayControlToUse
            DisplayControlToUse.ControlType = l_newMask
            AddHandler l_newMask.TextChanged, AddressOf l_MaskFloatChange
        End Sub

        ''' <summary>Supporting Method: Adds the specific control to the parent conrol.</summary>
        Private Sub AddControls()
            Dim StartHeight As Long = 0
            Dim curWidth As Long = 0

            MaxLabel = 0


            For Each curCtrl As dbiWSF.UserInterface.DisplayControl In Me.ControlsToAdd
                If Not curCtrl.ControlType Is Nothing Then


                    Dim newLabel As New System.Windows.Forms.Label
                    newLabel.Text = curCtrl.LabelString
                    newLabel.Top = StartHeight
                    newLabel.Left = 10
                    newLabel.AutoSize = True
                    curWidth = newLabel.PreferredWidth
                    StartHeight += curCtrl.ControlType.Height + 5
                    If MaxLabel < newLabel.PreferredWidth Then MaxLabel = newLabel.PreferredWidth
                    Me.Controls.Add(newLabel)

                    With curCtrl.ControlType
                        .Top = newLabel.Top
                        .Left = curWidth + 25
                    End With

                    Me.Controls.Add(curCtrl.ControlType)

                End If

            Next

            LayoutControls()
        End Sub

        ''' <summary>Supporting Method: Creates the layout and display for the specific controls.</summary>
        Private Sub LayoutControls()
            LastBottom = 0
            For Each Ctrl As System.Windows.Forms.Control In Me.Controls
                If Ctrl.GetType.ToString = GetType(Windows.Forms.Label).ToString Then
                    Dim curCtrl As Windows.Forms.Label = Ctrl
                    curCtrl.Left = curCtrl.Left + (MaxLabel - curCtrl.PreferredWidth)
                Else
                    Ctrl.Left = 10 + MaxLabel + 10 '(Initial left pos + maxlabelwidth + padding)
                End If
                LastBottom = Ctrl.Bottom
            Next
        End Sub
#End Region

#Region "**Raise Events**"
        ''' <summary>Raises the TextBoxChanged event.</summary>
        Public Sub l_TextBoxChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            RaiseEvent TextBoxChanged(sender, e)
        End Sub

        ''' <summary>Raises the TextBoxFloatChanged event.</summary>
        Public Sub l_TextBoxFloatChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            RaiseEvent TextBoxFloatChanged(sender, e)
        End Sub

        ''' <summary>Raises the NumericValueChanged event.</summary>
        Public Sub l_NumericValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            RaiseEvent NumericValueChanged(sender, e)
        End Sub

        ''' <summary>Raises the DateTimeChanged event.</summary>
        Public Sub l_DateTimeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            RaiseEvent DateTimeChanged(sender, e)
        End Sub

        ''' <summary>Raises the MaskFloatChanged event.</summary>
        Public Sub l_MaskFloatChange(ByVal sender As Object, ByVal e As System.EventArgs)
            RaiseEvent MaskFloatChanged(sender, e)
        End Sub

        ''' <summary>Raises the DaysOfWeekValidating event.</summary>
        Public Sub l_DaysOfWeekValidating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs, ByVal DaysOfWeek() As Byte)
            RaiseEvent DaysOfWeekValidating(sender, e, DaysOfWeek)
        End Sub
#End Region


    End Class
End Namespace
